<?php
/** ***********************
 * 作者：卢逸 www.61php.com
 * 日期：2015/5/21
 * 作用：视图模型
 ** ***********************/
class coreViewHome extends coreFrameworkView
{
	function index(){
		
		$this->login();
	}
	function login(){
		$this->dp("home/login");
	}
	
	function loginOut(){
		
		$this->GVar->session['user_info']='';
		$this->GVar->SetSessionData();
		if ($this->GVar->fget['is_ajax']) {
			echo 1;			
		}else{
			$url = "/core/login.html";
			MessageClass::ShowMessageComponent(_lang_logout_success,$url,1,_lang_del_fail,null,10);
		}
		
	}
	
	
	
	//登录验
	function checklogin(){
		$post=$this->GVar->fpost;
		$is_ajax = $this->GVar->fget['is_ajax'];
		if (!$post['username'] || !$post['password']){
			if ($is_ajax) {
				echo 0;
				die;
			}else{
				$url = "/core/login.html";
				MessageClass::ShowMessageComponent(_lang_login_fail,$url,1,_lang_del_fail,null,10);
				exit;
			}
			
		}
	
		$data=$this->model->checkUser($post);
		
		if ($data){
			$this->GVar->session['user_info']['id']=$data['id'];
			$this->GVar->session['user_info']['user_name']=$data['username'];
			$this->GVar->session['user_info']['gid']=$data['gid'];
			$this->GVar->SetSessionData();
		
			$ip=$_SERVER['REMOTE_ADDR'];
			//updata
			$login_data['logintime']=date("Y-m-d G:i:s");
			$login_data['loginip']=$ip;
			$login_data['session_id']=session_id();
		
			$this->model->updataUserLogin($login_data,$data['id']);
			//登陆记录
			$login['username']=$data['username'];
			$login['content']="User Login";
			//$data['username']=$this->user_root['user_name'];
			$login['op']="core";
			$login['task']="login";
			$login['type']="login";
			$login['ip']=$ip;
			$this->model->saveLog($login);
			
			if ($is_ajax) {
				echo 1;
				
			}else{
				$url = "/center/index.html";
				MessageClass::ShowMessageComponent(_lang_login_success,$url,1,_lang_del_fail,null,2);
			}
			
			
		}else{
			if ($is_ajax) {
				echo 0;
			}else{
				$url = "/core/login.html";
				MessageClass::ShowMessageComponent(_lang_login_fail,$url,1,_lang_del_fail,null,10);
			}
			
		}
		exit;
	}
	function ShowMessageComponent(){
		
		$msg = $this->GVar->session;
		$msg["url"] = $msg["success_url"];
		$msg["msg"] = $msg["success_msg"];
		$msg["use_script"] = 0;
		if (!$msg["result"])
		{
			$msg["url"] = $msg["fail_url"];
			$msg["msg"] = $msg["fail_msg"];
		}
	
		if (strtolower(substr($msg["url"],0,11))=="javascript:")
		{
			$msg["javascript"] = substr($msg["url"],11);
			$msg["use_script"] = 1;
		}
		$this->tmp->assign("msg",$msg);
		
		
		$this->dp("home/message");
	}

	//渠道中心登录验证
	function checkLoginChnnerUser(){
		$post=$this->GVar->fpost;
		$is_ajax = $this->GVar->fget['is_ajax'];
		if (!$post['name'] || !$post['password']){
			if ($is_ajax) {
				echo 0;
				die;
			}else{
				$url = "/core/login.html";
				MessageClass::ShowMessageComponent(_lang_login_fail,$url,1,_lang_del_fail,null,10);
				exit;
			}
			
			
		}
	
		$data=$this->model->checkChannelUser($post);
		if ($data){
			$this->GVar->session['user_info']['channel_id']=$data['channel_id'];
			$this->GVar->session['user_info']['channel_user_name']=$data['name'];
			$this->GVar->session['user_info']['header_img']=$data['header_img'];
			$this->GVar->session['user_info']['id']=$data['id'];
			$this->GVar->session['user_info']['gid']=$data['gid'];
			$this->GVar->SetSessionData();
		
			$ip=$_SERVER['REMOTE_ADDR'];
			//updata
			$login_data['logintime']=date("Y-m-d G:i:s");
			$login_data['loginip']=$ip;
			$login_data['session_id']=session_id();
		
			$this->model->updataUserLogin($login_data,$data['id']);
			//登陆记录
			$login['username']=$data['username'];
			$login['content']="User Login";
			//$data['username']=$this->user_root['user_name'];
			$login['op']="core";
			$login['task']="login";
			$login['type']="login";
			$login['ip']=$ip;
			$this->model->saveLog($login);
			
			if ($is_ajax) {
				echo 1;
				
			}else{
				$url = "/center/index.html";
				MessageClass::ShowMessageComponent(_lang_login_success,$url,1,_lang_del_fail,null,2);
			}
			
			
		}else{
			if ($is_ajax) {
				echo 0;
				
			}else{
				$url = "/core/login.html";
				MessageClass::ShowMessageComponent(_lang_login_fail,$url,1,_lang_del_fail,null,10);
			}
		
		}
		exit;
	}


}

?>